package org.example.controller;

import org.example.exception.BusinessException;
import org.example.pojo.Result;
import org.example.pojo.WxLoginQueryParam;
import org.example.service.LoginService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 登录功能前端控制器
 */
@Controller
public class LoginController {

    @Resource
    private LoginService loginService;

    @RequestMapping("/login")
    @ResponseBody
    public Result wxLogin(@RequestBody WxLoginQueryParam queryParam) throws IOException {
        String code = queryParam.getCode();
        //参数校验
        if (code == null || code.trim() == ""){
            throw  new BusinessException(500,"登录失败");
        }
        //调用业务层逻辑返回结果
        return loginService.login(code);
    }
    @GetMapping("/credit")
    @ResponseBody
    public Result getUserCredit(String token){
//调用业务层逻辑返回结果
        return loginService.getUserCredit(token);
    }
}